import { request } from "@/utils/service"
import exp from "constants"

export const getList = (model: string, where:any, page: number, size: number) => {
  return request({
    url: "admin/" + model + "/list",
    method: "get",
    params: { page, size, where }
  })
}

export const getColumn = (model: string) => {
  return request({
    url: "admin/" + model + "/getListColumns",
    method: "get"
  })
}

export const updateData = (model: string, data: []) => {
  return request({
    url: "admin/" + model + "/update",
    method: "POST",
    data
  })
}

export const deleteData = (model: string, id: number) => {
  return request({
    url: "admin/" + model + "/delete",
    method: "POST",
    params: { id }
  })
}

export const getFormColumns = (model: string, newData: boolean) => {
  return request({
    url: "admin/" + model + "/getFormColumns",
    method: "get",
    params: {
      newData
    }
  })
}

export const addData = (model: string, form: object) => {
  return request({
    url: "admin/" + model + "/add",
    method: "post",
    data: form
  })
}

export const getDetail = (model: string, id: number) => {
  return request({
    url: "admin/" + model + "/detail",
    method: "get",
    params: { id }
  })
}

export const getAuthStatus = (model: string,id: number) => {
  return request({
    url: "admin/" + model + "/authInfo",
    method: "get",
    params: { id }
  })
}

export const submitAuth = (model: string, id: number, form: any) => {
  form.id = id
  return request({
    url: "admin/" + model + "/submitAuth",
    method: "post",
    data: form 
  })
}

export const searchQuery = (url: string, query: string) => {
  return request({
    url: url,
    method: "get",
    params: { query }
  })
}